<!--
<template lang="jade">
.title
  h1 123
  el-button(type='primary', icon='delete' ,class="handle-del mr10", @click="$router.push('/push/new')")批量删除
  el-table(:data='data' border,style="width: 100%",ref="multipleTable" )
    el-table-column(prop='lastsno', label='Content')
    el-table-column(prop='node_id', label='CreateAt', width="150")
    el-table-column(prop='opertype', label=' SendAt', width="180")
    el-table-column(prop='lastsno', label='ID', width="100")
</template>
-->
<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-menu"></i> 数据源管理</el-breadcrumb-item>
                <el-breadcrumb-item>数据源列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="handle-box">
            <el-button type="primary" icon="delete" class="handle-del mr10" @click="delAll">批量删除</el-button>
             <el-button type="primary" icon="delete" class="handle-del mr10" @click="addOne">添加</el-button>
        </div>
        <div>
            <el-dialog title="新增数据源" :visible.sync="dialogFormVisible">
                <div class="form-box">
                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="标题">
                        <el-input v-model="form.title"></el-input>
                    </el-form-item>
                    <el-form-item label="内容">
                        <el-input type="textarea" v-model="form.content"></el-input>
                    </el-form-item>
                    <el-form-item label="智能内容">
                        <el-input type="textarea" v-model="form.ai_content"></el-input>
                    </el-form-item>
                    <el-form-item label="情感分析">
                        <el-input v-model="form.motion_score"></el-input>
                    </el-form-item>
                    <el-form-item label="智能关键字">
                        <el-input type="textarea" v-model="form.keyword_json"></el-input>
                    </el-form-item>
                    <el-form-item label="智能摘要">
                        <el-input type="textarea" v-model="form.summary_json"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="onSubmit">提交</el-button>
                        <el-button>取消</el-button>
                    </el-form-item>
                </el-form>
                </div>
            </el-dialog>
        </div>
        <el-table :data="data" border style="width: 100%" ref="multipleTable" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="title" label="资讯题目" width="120">
            </el-table-column>
            <el-table-column prop="ds_dt" label="资讯日期" width="120">
            </el-table-column>
            <el-table-column prop="motion_score" label="情感分数" width="120">
            </el-table-column>
            <el-table-column prop="keyword_str" label="关键词" width="120">
            </el-table-column>
            <el-table-column label="操作" width="180">
                <template slot-scope="scope">
                    <el-button size="small"
                            @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                    <el-button size="small" type="danger"
                            @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagination">
            <el-pagination
                    @current-change ="handleCurrentChange"
                    layout="prev, pager, next"
                    :total="1000">
            </el-pagination>
        </div>
    </div>
</template>

<script>

    //import {requestPost} from '../../utils/request'
    //import service from '../../utils/request'
    import {requestPost} from '@/utils/request'
    import service from '@/utils/request'

    export default {
        data() {
            return {
                url: './static/vuetable.json',
                tableData: [{
                    title: "test",
                    ds_dt: "mysql",
                    motion_score: "127.0.0.1",
                    summary_json: "3306"
                }],
                cur_page: 1,
                multipleSelection: [],
                select_cate: '',
                select_word: '',
                del_list: [],
                is_search: false,
                dialogFormVisible: false,
                action: -1,
                form: {

                }
            }
        },
        created(){
            this.getData();
        },
        computed: {
            data(){
                const self = this;
                return self.tableData;
                /*
                .filter(function(d){
                    let is_del = false;
                    for (let i = 0; i < self.del_list.length; i++) {
                        if(d.name === self.del_list[i].name){
                            is_del = true;
                            break;
                        }
                    }
                    if(!is_del){
                        if(d.address.indexOf(self.select_cate) > -1 &&
                            (d.name.indexOf(self.select_word) > -1 ||
                            d.address.indexOf(self.select_word) > -1)
                        ){
                            return d;
                        }
                    }
                })
                */
            }
        },
        methods: {
            handleCurrentChange(val){
                this.cur_page = val;
                this.getData();
            },
            getData(){
                let self = this;
                /*
                self.$axios({
                    method: 'post',
                    url: '/ioc_req',
                    data: {
                        SRVC_ID: '9210',
                        active: 4
                    }
                }).then(function(res) {
                    console.log(res.data.list);
                }).catch(function(error) {
                    console.log(error);
                });
                */

                //self.$axios.post('/ioc_req',


                service.post('/ioc_req',
                                 {SRVC_ID:"90101006",active:4}).then((res) => {

                    var tableData = res.data.data;
                    self.tableData = tableData;
                })

                /*
                {"SRVC_ID":"9210","active":4}:
                if(process.env.NODE_ENV === 'development'){
                    self.url = '/ms/table/list';
                };
                self.$axios.post(self.url, {page:self.cur_page}).then((res) => {
                    self.tableData = res.data.list;
                })
                */
            },
            search(){
                this.is_search = true;
            },
            formatter(row, column) {
                return row.address;
            },
            filterTag(value, row) {
                return row.tag === value;
            },
            handleEdit(index, row) {
                this.$message('编辑第'+(index+1)+'行');
                console.log('row',row);
                this.form = this.tableData[index]
                this.dialogFormVisible = true;
                this.action = 1;

            },
            handleDelete(index, row) {
                this.$message.error('删除第'+(index+1)+'行');
                //this.$axios.post('/ioc_req',
                service.post('/ioc_req',
                    {SRVC_ID:"90101009", ids: [this.tableData[index].id]}).then((res) => {
                        this.getData()
                    })
            },
            delAll(){
                const self = this,
                    length = self.multipleSelection.length;
                let str = '';
                self.del_list = self.del_list.concat(self.multipleSelection);
                for (let i = 0; i < length; i++) {
                    str += self.multipleSelection[i].name + ' ';
                }
                self.$message.error('删除了'+str);
                self.multipleSelection = [];
            },
            addOne() {
                this.dialogFormVisible = true;
                this.action = 0;
            },
            onSubmit() {
                this.form.SRVC_ID = "90101007";
                if (this.action == 0) {
                    this.form.id = '-1'
                }

                service.post('/ioc_req',
                this.form).then((res) => {
                    this.getData()
                    this.dialogFormVisible = false;
                })

            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            }
        }
    }
</script>

<style scoped>
.handle-box{
    margin-bottom: 20px;
}
.handle-select{
    width: 120px;
}
.handle-input{
    width: 300px;
    display: inline-block;
}
</style>
